
*Use this file to replicate the main results in the paper. Run this first, then run the R script to replicate Figure 1.


*Set working director and increase matsize
cd "C:\Users\kogan.18\Box\Monopsony"
set matsize 10999

*County-level analysis
use "county_seda_merge.dta", clear
gen avesal=totsalaries/totfte
gen aveben=totbenefits/totfte
gen avetotcost=(totsalaries+totbenefits)/totfte
gen avespend=totalexp12/newstucount
gen nonteach=(totalexp12-(totsalaries+totbenefits))/newstucount
gen teachratio=newstucount/totfte


gen logsal=ln(avesal)
gen logben=ln(aveben)
gen logtot=ln(avetotcost)
gen logspend=ln(avespend)
gen lognonteach=ln(nonteach)

gen NCLB=year>2001

gen hh1=hh<=0.1
gen hh2=hh<=0.2
replace hh2=0 if hh<=0.1
gen hh3=hh<=0.3
replace hh3=0 if hh<=0.2
gen hh4=hh<=0.4
replace hh4=0 if hh<=0.3
gen hh5=hh<=0.5
replace hh5=0 if hh<=0.4
gen hh6=hh<=0.6
replace hh6=0 if hh<=0.5
gen hh7=hh<=0.7
replace hh7=0 if hh<=0.6
gen hh8=hh<=0.8
replace hh8=0 if hh<=0.7
gen hh9=hh<=0.9
replace hh9=0 if hh<=0.8
gen hh10=hh<=1
replace hh10=0 if hh<=0.9

*2 percent of observations have average salaries over $120K
*0.05 percent of observations have sero oaverage salarie
drop if avesal>120000
drop if avesal==0
drop if white_share>100
drop if frl_share>100
gen logstaff=ln(totfte)


label variable hh "HHI"
label variable logsal "log(Salary)"
label variable logben "log(Benefits)"
label variable logtot "log(Tot. Compensation)"
label variable logspend "log(Tot. Spending per Student)"
label variable hh "HHI"
label variable dcount "District Count"
label variable white_share "White (% of Enrollment)"
label variable frl_share "Free/Reduced-Priced Lunch (% of Enrollment)"
label variable logstaff "log(Teacher FTEs)"

*Table 1, Top Panel
outreg2 using Table1_top.tex, tex replace sum(log) label keep(logsal logben logtot hh white_share frl_share logstaff)


*Table 2
xtset conum year
set more off
xtreg logsal hh i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using Table2.tex, tex replace ctitle(log(Salary)) label keep(hh)  addtext(County FE, Yes, Time FE, Years)
xtreg logben hh i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using Table2.tex, tex append ctitle(log(Benefits)) label keep(hh)  addtext(County FE, Yes, Time FE, Years)
set more off
xtreg logtot hh i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using Table2.tex, tex append ctitle(log(Tot. Comp.)) label keep(hh)  addtext(County FE, Yes, Time FE, Years)

*Table 4
xtreg logsal c.hh##CB i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using Table4.tex, tex replace ctitle(log(Salary)) label keep(c.hh##CB)  addtext(County FE, Yes, Time FE, Years)
xtreg logsal c.hh##i.Timing i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using Table4.tex, tex append ctitle(log(Salary)) label keep(c.hh##i.Timing)  addtext(County FE, Yes, Time FE, Years)
xtreg logsal c.hh##NCLB i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using Table4.tex, tex append ctitle(log(Salary)) label keep(c.hh##NCLB)  addtext(County FE, Yes, Time FE, Years)

*Data to create top panel of Figure 1
set more off
xtreg logsal hh2 hh3 hh4 hh5 hh6 hh7 hh8 hh9 hh10 i.year logstaff white_share frl_share , fe vce(cluster conum)
estimates store m1
esttab m1 using "hh_county.csv", replace plain keep(hh*) cells(b(nostar fmt(3)) ci(fmt(3))) level(95)

*Table A1
xtreg logsal hh i.year##i.State logstaff white_share frl_share, fe vce(cluster conum)
set more off
outreg2 using TableA1.tex, tex append ctitle(log(Salary)) label keep(hh)  addtext(County FE, Yes, Time FE, State-Years)
set more off
xtreg logben hh i.year##i.State logstaff white_share frl_share, fe vce(cluster conum)
set more off
outreg2 using TableA1.tex, tex append ctitle(log(Benefits)) label keep(hh)  addtext(County FE, Yes, Time FE, State-Years)
set more off
xtreg logtot hh i.year##i.State logstaff white_share frl_share, fe vce(cluster conum)
set more off
outreg2 using TableA1.tex, tex append ctitle(log(Tot. Comp.)) label keep(hh)  addtext(County FE, Yes, Time FE, State-Years)

*Table A2, Column 1
xtreg logsal L1.hh hh F.hh F2.hh F3.hh i.year logstaff white_share frl_share, fe vce(cluster conum)
outreg2 using TableA2_Col1.tex, tex replace ctitle(log(Salary.)) label keep(L1.hh hh F.hh F2.hh F3.hh)  addtext(Unit, County, Unit FE, X, Year FE, X)

*Table A4
set more off
xtreg logspend hh i.year white_share frl_share , fe vce(cluster conum)
outreg2 using TableA4.tex, tex replace ctitle(log(Tot. Spending per Student)) label keep(hh dcount)  addtext(County FE, Yes, Time FE, Years)
xtreg lognonteach hh i.year white_share frl_share , fe vce(cluster conum)
outreg2 using TableA4.tex, tex append ctitle(log(Non-Instructional Spending per Student)) label keep(hh dcount)  addtext(County FE, Yes, Time FE, Years)
xtreg logstaff hh i.year white_share frl_share , fe vce(cluster conum)
outreg2 using TableA4.tex, tex append ctitle(log(Teacher FTEs)) label keep(hh dcount)  addtext(County FE, Yes, Time FE, Years)
xtreg teachratio hh i.year white_share frl_share , fe vce(cluster conum)
outreg2 using TableA4.tex, tex append ctitle(Student-Teacher Ratio) label keep(hh dcount)  addtext(County FE, Yes, Time FE, Years)

*Table A5
set more off
xtreg logsal hh dcount i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using TableA5.tex, tex replace ctitle(log(Salary)) label keep(hh dcount)  addtext(County FE, Yes, Time FE, Years)
xtreg logben hh dcount i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using TableA5.tex, tex append ctitle(log(Benefits)) label keep(hh dcount)  addtext(County FE, Yes, Time FE, Years)
xtreg logtot hh dcount i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using TableA5.tex, tex append ctitle(log(Tot. Comp.)) label keep(hh dcount)  addtext(County FE, Yes, Time FE, Years)

*Table A6
xtreg g4_rla hh i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using TableA6.tex, tex replace ctitle(4th Grade ELA) label keep(hh)  addtext(County FE, Yes, Time FE, Years)
xtreg g8_rla hh i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using TableA6.tex, tex append ctitle(8th Grade ELA) label keep(hh)  addtext(County FE, Yes, Time FE, Years)
xtreg g4_mth hh i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using  TableA6.tex, tex append ctitle(4th Grade Math) label keep(hh)  addtext(County FE, Yes, Time FE, Years)
xtreg g8_mth hh i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using  TableA6.tex, tex append ctitle(8th Grade Math) label keep(hh)  addtext(County FE, Yes, Time FE, Years)

*Table A7
xtreg g4_rla hh i.year##i.State logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using TableA7.tex, tex replace ctitle(4th Grade ELA) label keep(hh)  addtext(County FE, Yes, Time FE, Years)
xtreg g8_rla hh i.year##i.State logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using TableA7.tex, tex append ctitle(8th Grade ELA) label keep(hh)  addtext(County FE, Yes, Time FE, Years)
xtreg g4_mth hh i.year##i.State logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using TableA7.tex, tex append ctitle(4th Grade Math) label keep(hh)  addtext(County FE, Yes, Time FE, Years)
xtreg g8_mth hh i.year##i.State logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using TableA7.tex, tex append ctitle(8th Grade Math) label keep(hh)  addtext(County FE, Yes, Time FE, Years)

*Table A8
gen prod4=(g4_rla+g4_mth)/2/(avespend/1000)
gen prod8=(g8_rla+g8_mth)/2/(avespend/1000)
set more off
xtreg prod4 hh i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using TableA8.tex, tex replace ctitle(prod4) label keep(hh)  addtext(County FE, Yes, Time FE, Years)
xtreg prod8 hh i.year logstaff white_share frl_share , fe vce(cluster conum)
outreg2 using TableA8.tex, tex append ctitle(prod8) label keep(hh)  addtext(County FE, Yes, Time FE, Years)


*District-level analysis
*Use this one
set matsize 11000
use "district_data.dta", clear
drop if avesal>120000
drop if avesal==0
drop if white_share>100
drop if frl_share>100
drop if teachfte<1
gen one=hh==1
gen logstaff=ln(teachfte)

gen hh1=hh<=0.1
gen hh2=hh<=0.2
replace hh2=0 if hh<=0.1
gen hh3=hh<=0.3
replace hh3=0 if hh<=0.2
gen hh4=hh<=0.4
replace hh4=0 if hh<=0.3
gen hh5=hh<=0.5
replace hh5=0 if hh<=0.4
gen hh6=hh<=0.6
replace hh6=0 if hh<=0.5
gen hh7=hh<=0.7
replace hh7=0 if hh<=0.6
gen hh8=hh<=0.8
replace hh8=0 if hh<=0.7
gen hh9=hh<=0.9
replace hh9=0 if hh<=0.8
gen hh10=hh<=1
replace hh10=0 if hh<=0.9

gen logsal=ln(avesal)
gen logben=ln(aveben)


label variable logsal "log(Salary)"
label variable hh "HHI"
label variable white_share "White (% of Enrollment)"
label variable frl_share "Free/Reduced-Priced Lunch (% of Enrollment)"
label variable logstaff "log(Teacher FTEs)"
label variable MarketShare "Market Share"

*Table 1, Top Panel
outreg2 using Table1_bottom.tex, tex replace sum(log) label keep(logsal hh white_share frl_share logstaff MarketShare)

*Table 3
xtset leaid year
set more off
xtreg logsal hh i.year logstaff white_share frl_share , fe vce(cluster leaid)
outreg2 using Table3.tex, tex replace ctitle(log(Salary)) label keep(hh)  addtext(County FE, Yes, Time FE, Years)
set more off
xtreg logsal hh MarketShare i.year logstaff white_share frl_share , fe vce(cluster leaid)
outreg2 using Table3.tex, tex append ctitle(log(Salary)) label keep(hh MarketShare)  addtext(County FE, Yes, Time FE, Years)

*Data to create bottom panel of Figure 1
xtreg logsal hh2 hh3 hh4 hh5 hh6 hh7 hh8 hh9 hh10 i.year logstaff white_share frl_share , fe vce(cluster leaid)
estimates store m1
esttab m1 using "hh_district.csv", replace plain keep(hh*) cells(b(nostar fmt(3)) ci(fmt(3))) level(95)

*Table A2, Column 2
set more off
xtreg logsal L1.hh hh F.hh F2.hh F3.hh i.year logstaff white_share frl_share , fe vce(cluster leaid)
outreg2 using Table2A_Col2.tex, tex append ctitle(log(Tot. Comp.)) label keep(L1.hh hh F.hh F2.hh F3.hh)  addtext(Unit, District, Unit FE, X, Year FE, X)
